﻿using DotNetNuke.Web.Api;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace DNNDev.DNNModules.NewsBeast.Services
{
    public class ServiceController : DnnApiController
    {
        #region Item

        [AllowAnonymous]
        [HttpPost]
        public HttpResponseMessage InsertItem(ItemInfo item)
        {
            NewsBeastController controller = new NewsBeastController();
            item = controller.InsertItem(item);
            return Request.CreateResponse(HttpStatusCode.OK, item);
        }

        [AllowAnonymous]
        [HttpPost]
        public HttpResponseMessage UpdateItem(ItemInfo item)
        {
            NewsBeastController controller = new NewsBeastController();
            item = controller.UpdateItem(item);
            return Request.CreateResponse(HttpStatusCode.OK, item);
        }

        [AllowAnonymous]
        [HttpPost]
        public HttpResponseMessage DeleteItem(ItemInfo item)
        {
            NewsBeastController controller = new NewsBeastController();
            controller.DeleteItem(item);
            return Request.CreateResponse(HttpStatusCode.OK);
        }

        [AllowAnonymous]
        [HttpGet]
        public HttpResponseMessage GetAllItems(int moduleId)
        {
            NewsBeastController controller = new NewsBeastController();
            IEnumerable<ItemInfo> items = controller.GetAllItems(moduleId);
            return Request.CreateResponse(HttpStatusCode.OK, items);
        }

        #endregion item


        #region Subscriber

        [AllowAnonymous]
        [HttpPost]
        public HttpResponseMessage InsertSubscriber(SubscriberInfo item)
        {
            NewsBeastController controller = new NewsBeastController();
            item.ID = controller.InsertNL_Subscriber(item);
            return Request.CreateResponse(HttpStatusCode.OK, item);
        }

        #endregion

        #region Newsletter

        [AllowAnonymous]
        [HttpGet]
        public HttpResponseMessage getAllNewsletters()
        {
            NewsBeastController controller = new NewsBeastController();
            IEnumerable<NewsletterInfo> items = controller.GetNL_Newsletters();
            return Request.CreateResponse(HttpStatusCode.OK, items);
        }

        [AllowAnonymous]
        [HttpPost]
        public HttpResponseMessage DeleteNewsletter(NewsletterInfo item)
        {
            NewsBeastController controller = new NewsBeastController();
            controller.DeleteNL_Newsletter(item);
            return Request.CreateResponse(HttpStatusCode.OK);
        }

        [AllowAnonymous]
        [HttpPost]
        public HttpResponseMessage InsertNewsletter(NewsletterInfo item)
        {
            NewsBeastController controller = new NewsBeastController();
            item.ID = controller.InsertNL_Newsletter(item);
            return Request.CreateResponse(HttpStatusCode.OK, item);
        }

        [AllowAnonymous]
        [HttpPost]
        public HttpResponseMessage UpdateNewsletter(NewsletterInfo item)
        {
            NewsBeastController controller = new NewsBeastController();
            controller.UpdateNL_Newsletter(item);
            return Request.CreateResponse(HttpStatusCode.OK, item);
        }


        #endregion
    }
}